package com.surprise.db.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import com.surprise.db.entity.CUser;

/**
 * UserRepository.java
 * @author nick
 * @since 2017年1月11日
**/
public interface UserRepository extends JpaRepository<CUser, Long> {
	
	 @Modifying(clearAutomatically = true)
	 @Transactional
	 @Query(value="update user o set o.integral=:ks where o.id = :id")
	 public int update(@Param("ks") long d,@Param("id") long k);
	 
	 @Query("select id from user bean where bean.phone = ?1")
	 public long findIdByPhone(String phone);
	 
	 @Modifying
	 @Transactional
	 @Query(value="update user o set o.portrait=:portrait, o.username=:username, o.updatetime = now() where o.id = :id")
	 public int updateInfo(@Param("portrait") String portrait, @Param("username") String username,
			 @Param("id") long id);
}
